let baseUrl
let domainUrl

if (process.env.NODE_ENV === 'development') {
	//本地路径
	//baseUrl = '/api/'
	//baseUrl = 'https://ysxq.taobowlkj.com/api/'
	//domainUrl = 'https://ysxq.taobowlkj.com'
	baseUrl = 'https://test.taobowlkj.com/api/'
	domainUrl = 'https://test.taobowlkj.com'
} else {
	//线上路径
	baseUrl = 'https://ysxq.taobowlkj.com/api/'
	domainUrl = 'https://ysxq.taobowlkj.com'
	//baseUrl = 'https://test.taobowlkj.com/api/'
	//domainUrl = 'https://test.taobowlkj.com'
}


baseUrl = 'https://ysxq.taobowlkj.com/api/'
domainUrl = 'https://ysxq.taobowlkj.com'



const post = (url, data, hideloding) => {
	let token = uni.getStorageSync("app_token")

	//获取当前设置的语言
	let lang = uni.getLocale()
	if (lang == 'zh-Hans') { //中文简体
		lang = 'zh-cn'
	}

	let httpDefaultOpts = {
		url: baseUrl + url + '?lang=' + lang,
		data: data,
		method: "POST",
		header: {
			'Accept': 'application/json',
			'Content-Type': 'application/x-www-form-urlencoded',
			'token': token
		},
		dataType: 'json',
	}
	let promise = new Promise(function(resolve, reject) {
		uni.request(httpDefaultOpts).then(
			(ret) => {
				if (ret.data.code === 401) {
					reject(ret)
				} else {
					resolve(ret.data)
				}
			}
		)
	})
	return promise
};

const get = (url, data, hideloding) => {
	let httpDefaultOpts = ''
	let token = uni.getStorageSync("app_token")

	//获取当前设置的语言
	let lang = uni.getLocale()
	if (lang == 'zh-Hans') { //中文简体
		lang = 'zh-cn'
	}

	httpDefaultOpts = {
		url: baseUrl + url + '?lang=' + lang,
		method: "GET",
		data: data,
		header: {
			'Accept': 'application/json',
			'Content-Type': 'application/x-www-form-urlencoded',
			'token': token
		},
		dataType: 'json',
	}
	let promise = new Promise(function(resolve, reject) {
		uni.request(httpDefaultOpts).then(
			(ret) => {
				if (ret.data.code === 401) {
					reject(ret)
				} else {
					resolve(ret.data)
				}
			}
		)
	})
	return promise
};
export default {
	post,
	get,
	baseUrl,
	domainUrl
}